from ddt import ddt, data, unpack
from unittest import TestCase
from selenium import webdriver
from EditCardData import EditCardData
from EditCardOperation import EditCardOperation
from DBUtils import DBUtils


@ddt
class TestDeleteCard(TestCase):
    @data(*EditCardData.editcard_name_data)
    @unpack
    def testEditCard1(self, casename, username, password, bankname, expect):
        # 开始测试
        driver = webdriver.Chrome()
        # 打开浏览器页面并最大化
        driver.get("http://localhost:90")
        driver.maximize_window()

        dbutils = DBUtils()
        before_result = dbutils.select('select id from bankcard where cardBank = "伊拉克国民银行" and cardNum = "1234567891548790" and type = "1"')
        print(before_result)
        # 执行删除
        editcard = EditCardOperation()
        editcard.editcard_name(driver, username, str(int(password)), bankname)
        # 获取删除实际结果
        result = editcard.editcard_name_result(before_result[0][0], bankname)
        if result != int(expect):
            driver.save_screenshot(casename + '.jpg')
        else:
            print('通过')

        driver.quit()

        self.assertEqual(result, int(expect))

    @data(*EditCardData.editcard_num_data)
    @unpack
    def testEditCard2(self, casename, username, password, cardnum, expect):
        # 开始测试
        driver = webdriver.Chrome()
        # 打开浏览器页面并最大化
        driver.get("http://localhost:90")
        driver.maximize_window()

        dbutils = DBUtils()
        before_result = dbutils.select(
            'select id from bankcard where cardBank = "啊啊啊" and cardNum = "1234567891548790" and type = "1"')

        # 执行删除
        editcard = EditCardOperation()
        editcard.editcard_num(driver, username, str(int(password)), cardnum)
        # 获取删除实际结果
        result = editcard.editcard_num_result(before_result[0][0], cardnum)
        if result != int(expect):
            driver.save_screenshot(casename + '.jpg')
        else:
            print('通过')

        driver.quit()

        self.assertEqual(result, int(expect))

    @data(*EditCardData.editcard_illegalnum_data)
    @unpack
    def testEditCard3(self, casename, username, password, illnum, expect):
        # 开始测试
        driver = webdriver.Chrome()
        # 打开浏览器页面并最大化
        driver.get("http://localhost:90")
        driver.maximize_window()

        dbutils = DBUtils()
        before_result = dbutils.select(
            'select id from bankcard where cardBank = "啊啊啊" and cardNum = "1111111111111111" and type = "1"')

        # 执行删除
        editcard = EditCardOperation()
        editcard.editcard_illegalnum(driver, username, str(int(password)), illnum)
        # 获取删除实际结果
        result = editcard.editcard_illnum_result(before_result[0][0], illnum)
        if result != int(expect):
            driver.save_screenshot(casename + '.jpg')
        else:
            print('通过')

        driver.quit()

        self.assertEqual(result, int(expect))

    @data(*EditCardData.editcard_type_data)
    @unpack
    def testEditCard4(self, casename, username, password, cardtype, expect):
        # 开始测试
        driver = webdriver.Chrome()
        # 打开浏览器页面并最大化
        driver.get("http://localhost:90")
        driver.maximize_window()

        dbutils = DBUtils()
        before_result = dbutils.select(
            'select id from bankcard where cardBank = "啊啊啊" and cardNum = "22222222222222222" and type = "1"')

        # 执行删除
        editcard = EditCardOperation()
        editcard.editcard_type(driver, username, str(int(password)), cardtype)
        # 获取删除实际结果
        result = editcard.editcard_type_result(before_result[0][0], cardtype)
        if result != int(expect):
            driver.save_screenshot(casename + '.jpg')
        else:
            print('通过')

        driver.quit()

        self.assertEqual(result, int(expect))
